package com.georgekozlovsky.math;

import javax.jws.WebService;

@WebService(targetNamespace = "http://math.georgekozlovsky.com/", portName = "FibonacciPort", serviceName = "FibonacciService")
public class Fibonacci {
	public long calculate(int n) {
		long [] buffer = {0l, 1l};
		long result = 0;

		if (n > 0 && n < 3) {
			result = buffer[n - 1];
		} else {

			for (int i = 1; i < n - 1; i++) {
				result = buffer[1] + buffer[0];
				buffer[0] = buffer[1];
				buffer[1] = result;
			}
		}
		return result;
	}
}
